<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/conn.asp"-->
<!--#include file="lib/saferequest.asp"-->
<!--#include file="lib/error_write.asp"-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<link rel="stylesheet" href="lib/sheet.css" type="text/css" />
<link type="text/css" rel="stylesheet" href="lib/ui/themes/base/ui.all.css" />
<!-- jquery和ui -->
<script type="text/javascript" src="lib/jquery.js"></script>
<script type="text/javascript" src="lib/ui/ui.core.js"></script>
<script type="text/javascript" src="lib/ui/ui.datepicker.js"></script>
<script type="text/javascript" src="lib/ui/i18n/ui.datepicker-zh-CN.js"></script>
<script type="text/javascript">
	$(function() {
		$.datepicker.setDefaults({
			changeMonth: true,
			changeYear: true
		});
		$(".datepicker").datepicker();
		$(".contable").addClass("ct");	//载入table样式
		$(".contable th").addClass("ch");	//载入th样式
		$(".contable td").addClass("ld");	//载入td样式
		$("#dd,#xx").change(function(){
			$.get("yj.asp",{didian:$("#dd").val(),xiangxing:$("#xx").val()},function(data){
				//alert(data);
				if (!data){
					$("#yj,#jsj").val(0);
					return false;
				}
				$("#yj").val(data.yunjia);
				$("#zdyj").html(data.yunjia);

				//$("#rlf,#sjrlf").val(data.zdrlf);
				if(data.jsj==""){$("#jsj").val("0")} else {$("#jsj").val(data.jsj)};
				$("#dz").val((parseFloat($("#jgf").val())+parseFloat($("#jsj").val()))*0.6);
				
			},"json");
		});
		$("#tixiang,#huanxiang").change(function(){
			var tx=hx=0;
			$.get("tx.asp",{tx:$("#tixiang").val()},function(data){
				//alert(data);
				(!data)? tx=0 : tx=data.tx;
				$("#jgf").val(tx+hx);
				$("#dz").val((tx+hx+parseFloat($("#jsj").val()))*0.6);
			},"json");
			$.get("hx.asp",{hx:$("#huanxiang").val()},function(data){
				//alert(data);
				(!data)? hx=0 : hx=data.hx;
				$("#jgf").val(tx+hx);
				$("#dz").val((tx+hx+parseFloat($("#jsj").val()))*0.6);
			},"json");
		});
		var j=-1;
		function getkeycode(e){
			var keyc;
			if(window.event){
				keyc=e.keyCode;
			}else if(e.which){
				keyc=e.which;
			}
			return keyc;
		}

		function tyrover(n,mn){
			for(var i=0;i<mn;i++){
				if(i>=0&&i<mn&&i==n){
					$("#ttyr tr").eq(i).addClass("gac_b");	//添加css样式
				}else{
					$("#ttyr tr").eq(i).removeClass("gac_b");	//添加css样式
				}

			}

		}

		$("#tyr").keyup(function(e){
			var tyr=$("#tyr");
			if(getkeycode(e)==13||getkeycode(e)==38||getkeycode(e)==40){
				var	ttr=$("#ttyr tr");
				if(getkeycode(e)==13&&($("#ttyr").css("visibility")=="visible")) {
					//alert(j);
					tyr.val(ttr.eq(j).text());
					j=-1;
					$("#ttyr").css("visibility","hidden");
				}
				if(getkeycode(e)==40){
					j++;
					if(j>=ttr.length) j=0;
					tyr.val(ttr.eq(j).text());
					tyrover(j,ttr.length);
				}else	if(getkeycode(e)==38){
					j--;
					if(j==-1) j=ttr.length-1;
					tyr.val(ttr.eq(j).text());
					tyrover(j,ttr.length);
				}
				return;
			}
			$("#ttyr").css("left",tyr.offset().left).css("top",tyr.offset().top+tyr.outerHeight()-1).width(tyr.outerWidth());	//outerHeight()有margin是否选中的选项，注意！
			//$("#ttyr").css("left",(tyr.offset().left).toString()+"px").css("top",(tyr.offset().top+tyr.height()+5).toString()+"px").css("width",(tyr.width()+6).toString()+"px");	//原先的定位代码
			//		alert(tyr.offset().left);
			//e.preventDefault();
			if(tyr.val().length>0){	//输入框内容大于0就开始查询
				$.get("tyr.asp",{tyr:$(this).val()},function(data){
					if(!data.length){
						j=-1;
						$("#ttyr").css("visibility","hidden");
					}else{
						//alert(data[0].tyr);

						var ttyr="";
						for(var i=0;i<data.length;i++)	//for(var i=0;i<data.length&&i<=10;i++)最多显示10条，也可以通过数据库控制返回最多10条
						{
							ttyr+="<tr><td class='gac_c'>"+data[i].tyr+"</td></tr>";
							//alert(ttyr);
						}
						//alert(ttyr);
						$("#ttyr").html(ttyr).css("visibility","visible");
						$("#ttyr tr").mouseover(function(){	//对返回的dom进行mouseowver事件捕获
							$("#ttyr tr").eq(j).removeClass("gac_b");
							$(this).addClass("gac_b");	//添加css样式
							j=$("#ttyr tr").index($(this));
						}).mouseout(function(){	//对dom进行mouseout事件捕获
							$(this).removeClass("gac_b");	//移除css样式
						}).click(function(){
							tyr.val($(this).text());
							j=-1;
							$("#ttyr").css("visibility","hidden");
						});
						tyr.blur(function(){
							j=-1;
							setTimeout("$('#ttyr').css('visibility','hidden');", 200);	//设置延时隐藏列表的时间，以便有时间让click事件能取得数据
						});
					}
				},"json");
			}else{
				j=-1;
				$("#ttyr").css("visibility","hidden");	//输入框没有内容时隐藏提示框
			}
		}).keydown(function(e){
			if(getkeycode(e)==13) return false;
		});
	});
</script>

<!--#include file="lib/keydown.asp"-->

</head>
<%
If Not Session("MM_Reg") Then
	response.write("您没有登陆，请登陆后使用!<br>")
	response.write "<a href='javascript:history.go(-1)'> << 返回上一页</a><br> "
	response.end
End If
if Session("MM_Flag")<4 then
	response.write("您没有添加权限！<br>")
	response.write "<a href='javascript:history.go(-1)'> << 返回上一页</a><br> "
	response.End
end if
if Session("MM_Post")<>1 And Session("MM_Post")<>0 Then
	response.write("您没有此岗位操作权限！<br>")
	response.write "<a href='javascript:history.go(-1)'> << 返回上一页</a><br> "
	response.End
end If
%>
<body>
<%
if request.form("tj")="下单" or request.form("tj")="保存" Then
	if request.form("tj")="下单" Then post=2
	if request.form("tj")="保存" Then post=1
	client=trim(SafeRequest("client",0))
	contacts=trim(SafeRequest("contacts",0))
	hz=trim(SafeRequest("hz",0))
	attentions=trim(SafeRequest("attentions",0))
	xdr=trim(SafeRequest("xdr",0))
	if xdr="" then error_write "3","没有填写[下单人]"
	sj=trim(SafeRequest("sj",0))
	rq=trim(SafeRequest("rq",0))
	if rq="" then error_write "1","没有填写[日期]"
	xdrq=trim(SafeRequest("xdrq",0))
	if xdrq="" then error_write "4","没有填写[下单日期]"
	tyr=trim(SafeRequest("tyr",0))
	if tyr="" then error_write "2","没有填写[托运人]"
	dd=trim(SafeRequest("dd",0))
	cmhc=trim(SafeRequest("cmhc",0))
	tdh=trim(SafeRequest("tdh",0))
	xx=trim(SafeRequest("xx",0))
	lrsj=trim(SafeRequest("lrsj",0))
	if lrsj="" then error_write "23","没有填写[录入日期]"
	tx=trim(SafeRequest("tixiang",0))
	hx=trim(SafeRequest("huanxiang",0))
	yj=trim(SafeRequest("yj",0))
	if yj="" then yj=0
	jsj=trim(SafeRequest("jsj",0))
	if jsj="" then jsj=0
	jgf=trim(SafeRequest("jgf",0))
	if jgf="" then jgf=0
	dz=trim(SafeRequest("dz",0))
	if dz="" then dz=0
	sql="insert into yb(sj,rq,tyr,dd,cmhc,tdh,xx,lrsj,client,contacts,hz,attentions,gxry,post,xdrq,xdr,xdrid,tx,hx,yj,jsj,jgf,dz) values('"&sj&"','"&rq&"','"&tyr&"','"&dd&"','"&cmhc&"','"&tdh&"','"&xx&"','"&lrsj&"','"&client&"','"&contacts&"','"&hz&"','"&attentions&"','"&session("MM_Name")&"',"&post&",'"&xdrq&"','"&xdr&"',"&session("MM_ID")&",'"&tx&"','"&hx&"',"&yj&","&jsj&","&jgf&","&dz&")"
	response.write sql
	'response.end
	set cmd=Server.CreateObject("ADODB.Command")
	cmd.ActiveConnection=conn
	cmd.CommandText = sql
	cmd.Execute
	response.write("下单成功，可以继续添加下一条，察看添加的数据请返回！")
	'response.end
	set rs_new=server.createobject("adodb.recordset")
	sql_new="select id from yb where id=(select max(id) as Last_Id from yb)"
	rs_new.open sql_new,conn,1,1
	id=rs_new("id")
	rs_new.close
	view_url="view_cw.asp?id="&id
	response.Redirect(view_url)
end if

%>
<form name="form1" method="post" action="#">
<table class="contable">
	<thead>
		<tr>
			<th colspan="4" class="lh"><font size="4">基本信息</font>(录入时间:<input class="datepicker" name="lrsj" id="lrsj" size="10" value="<%=date()%>" />&nbsp;下单人:<input name="xdr" id="xdr" size="10" readonly="readonly" value="<%=session("MM_Name")%>" />)
			</th>
		</tr>
	</thead>
  <tr>
    <th>详细厂名</th>
    <td colspan="3"><input name="client" id="client" size="80" /></td>
	</tr>
	<tr>
    <th>联系方式</th>
    <td colspan="3"><input name="contacts" id="contacts" size="80" /></td>
	</tr>
	<tr>
    <th>货主</th>
    <td colspan="3"><input name="hz" id="hz" size="80" /></td>
	</tr>
  <tr>
    <th>托运人</th>
    <td><select id="tyr" name="tyr">
		<%
		set rs_tyr = Server.CreateObject("ADODB.Recordset")
sql="select tyr from (select tyr,count(tyr) as n from yb group by tyr) order by n desc"
rs_tyr.open sql,conn,1,1
While Not rs_tyr.eof
%>
	 <option value="<%=rs_tyr("tyr")%>" <%if rs_tyr("tyr")="托浦" then response.write("selected")%>><%=rs_tyr("tyr")%></option>
<%
rs_tyr.movenext
Wend
rs_tyr.close
%>					
		</select>
</td>
    <th>货单日期</th>
    <td><input class="datepicker" name="rq" id="rq" value="<%=date()%>" /></td>
  </tr>
  <tr>
    <th>地点</th>
    <td>
	  <select name="dd" id="dd">
        <option value=""></option>
		<%
		set rs_dd = Server.CreateObject("ADODB.Recordset")
		sql="select didian from yj group by didian"
		rs_dd.open sql,conn,1,1
		while not rs_dd.eof
		%>
        <option value="<%=rs_dd("didian")%>"><%=rs_dd("didian")%></option>
	<%
			rs_dd.movenext()
		wend
		rs_dd.close
	%>
      </select>
		</td>
		<th>时间</th>
		<td>
		<select id="sj" name="sj">
			<option value="0:00">0:00</option>
			<option value="1:00">1:00</option>
			<option value="2:00">2:00</option>
			<option value="3:00">3:00</option>
			<option value="4:00">4:00</option>
			<option value="5:00">5:00</option>
			<option value="6:00">6:00</option>
			<option value="7:00">7:00</option>
			<option value="8:00">8:00</option>
			<option value="9:00">9:00</option>
			<option value="10:00">10:00</option>
			<option value="11:00">11:00</option>
			<option value="12:00">12:00</option>
			<option value="13:00">13:00</option>
			<option value="14:00">14:00</option>
			<option value="15:00">15:00</option>
			<option value="16:00">16:00</option>
			<option value="17:00">17:00</option>
			<option value="18:00">18:00</option>
			<option value="19:00">19:00</option>
			<option value="20:00">20:00</option>
			<option value="21:00">21:00</option>
			<option value="22:00">22:00</option>
			<option value="23:00">23:00</option>
		</select>
	</td>
	</tr>
	<tr>
    <th>船名/航次</th>
    <td><input name="cmhc" id="cmhc" /></td>
		<th>下单日期</th>
		<td><input class="datepicker" name="xdrq" id="xdrq" value="<%=date()%>">
		</td>
  </tr>
  <tr>
    <th>提单号</th>
    <td><input name="tdh" id="tdh" /></td>
    <th>箱型</th>
    <td>
		<select name="xx" id="xx">
        <option value="40">40</option>
        <option value="20">20</option>
        <option value="45">45</option>
		</select>
	  </td>
  </tr>
  <tr>
    <th>提箱</th>
    <td>
		<select name="tixiang" id="tixiang">
        <option value=""></option>
		<%
		set rs_tx = Server.CreateObject("ADODB.Recordset")
		sql="select * from tx"
		rs_tx.open sql,conn,1,1
		while not rs_tx.eof
		%>
        <option value="<%=rs_tx("tixiang")%>" ><%response.write(rs_tx("tixiang")&"("&rs_tx("tixiangjiage")&")")%></option>
	<%
			rs_tx.movenext()
		wend
		rs_tx.close
	%>
      </select>
</td>
    <th>还箱</th>
    <td>
	<select name="huanxiang" id="huanxiang">
        <option value=""></option>
		<%
		set rs_hx = Server.CreateObject("ADODB.Recordset")
		sql="select * from hx"
		rs_hx.open sql,conn,1,1
		while not rs_hx.eof
		%>
        <option value="<%=rs_hx("huanxiang")%>" ><%response.write(rs_hx("huanxiang")&"("&rs_hx("huanxiangjiage")&")")%></option>
	<%
			rs_hx.movenext()
		wend
		rs_hx.close
	%>
      </select>
</td>
  </tr>
  <tr>
    <th>注意事项</th>
    <td colspan="3"><input name="attentions" id="attentions" size="80" /></td>
	</tr>
</table>
<br />
<div style="display:none">
应收运价：<input name="yj" id="yj" readonly="readonly" value="0" /> 运价:<span id="zdyj"></span> 运价=地点&amp;箱型
<br />
应付运价：<input name="jsj" id="jsj" readonly="readonly" value="0" />
<br />
进港费：<input name="jgf" id="jgf" readonly="readonly" value="0" /> 进港费=提箱+还箱
<br />
垫资：<input name="dz" id="dz" readonly="readonly" title="垫资=（应付运费+进港费）×60%" value="0" /> 
</div>
<input class="bt" type="submit" name="tj" value="保存" />&nbsp;&nbsp;&nbsp;&nbsp;<input class="bt" type="submit" name="tj" value="下单" onClick="return confirm('确定下单吗？');" />&nbsp;&nbsp;&nbsp;&nbsp;<input class="bt" type="reset" />
</form>


</body>
<%
conn.close
Set conn=nothing
%>
</html>
